<?php

if (!isset($_SESSION['logged']) || $_SESSION['level'] != "admin")
    print "<script language='javascript'>
        window.location.href='./?url=404';
        </script>";
else {
    $idtype = $_GET['type'];

    $sql = "SELECT * FROM `file` WHERE `type_id` = '$idtype';";
    $result = mysql_query($sql, $link);
    if (mysql_num_rows($result) == 0) {
        $sql = "DELETE FROM `type` WHERE `id` = '$idtype';";
        $result = mysql_query($sql, $link);
        print "<script language='javascript'>
        alert('The item was deleted successfully.');
        window.location.href='./';
        </script>";
    } else {
        print "<script language='javascript'>
        alert('The item was not deleted because there are files set as this type.');
        window.location.href='./';
        </script>";
    }
}
?>
